/* Copyright 2012 Dustin Mitchell <dmmitche [at] gmail [dot] com>
 *
 * Licensed under the GPLv3.  See included LICENSE.txt for full details.
 */

#ifndef __MESSAGE_HANDLER__
#define __MESSAGE_HANDLER__

#include "sync_queue.h"
#include "ref_cnt.h"
#include "messages.h"

struct message_handler
{
  struct sync_queue msg_queue;
};

int message_handler_create (struct message_handler *handler);

void message_handler_destroy (struct message_handler *handler);

/* Should only be called by a message_queue object */
int message_handler_post (struct message_handler *handler,
                          struct ref_cnt *msg);

int message_handler_wait (struct message_handler *handler,
                          union message *msg);

/* Returns a 1 if a message was removed */
int message_handler_peek (struct message_handler *handler,
                          union message *msg);

#endif /* __MESSAGE_HANDLER__ */
